package generator.config;

import cn.hutool.core.util.StrUtil;
import generator.config.rules.IJavaType;
import generator.config.rules.ITypeConvert;

/**
 * <p>
 *
 * </p>
 *
 * @author angel.bin@aliyun.com
 * @since 2020-10-05 13:54
 */
public class MysqlTypeConvert implements ITypeConvert {
    @Override
    public IJavaType processTypeConvert(String type) {
        type = type.toLowerCase();
        if (StrUtil.containsAnyIgnoreCase(type, "char", "text", "json", "enum")) {
            return JavaType.STRING;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "bigint")) {
            return JavaType.LONG;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "tinyint(1)", "bit")) {
            return JavaType.BOOLEAN;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "int")) {
            return JavaType.INTEGER;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "decimal")) {
            return JavaType.BIG_DECIMAL;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "clob")) {
            return JavaType.CLOB;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "blob")) {
            return JavaType.BLOB;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "binary")) {
            return JavaType.BYTE_ARRAY;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "float")) {
            return JavaType.FLOAT;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "double")) {
            return JavaType.DOUBLE;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "year")) {
            return JavaType.YEAR;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "datetime")) {
            return JavaType.LOCAL_DATE_TIME;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "date")) {
            return JavaType.LOCAL_DATE;
        }
        if (StrUtil.containsAnyIgnoreCase(type, "time")) {
            return JavaType.LOCAL_TIME;
        }
        return JavaType.STRING;
    }
}
